// 所有的页面引入
import { lazyLoad, load, redirect, setRouteBefore } from '@/router/utilsFn/fn'
export const lazyRoutes = {
  option1:lazyLoad(() => import('@/pages/option/options1'), { title: 'options11', needLogin: true }),// 懒加载
  option21:lazyLoad(() => import('@/pages/option/options2'), { title: 'options12', needLogin: true }),// 懒加载
  option31:lazyLoad(() => import('@/pages/option/options3'), { title: 'options13', needLogin: true }),// 懒加载
  option32:lazyLoad(() => import('@/pages/option/options5'), { title: 'options15', needLogin: true }),// 懒加载
  // option6:lazyLoad(() => import('@/pages/option/options6'), { title: 'options16', needLogin: true }),// 懒加载
  // option7:lazyLoad(() => import('@/pages/option/options7'), { title: 'options17', needLogin: true }),// 懒加载
  // option8:lazyLoad(() => import('@/pages/option/options8'), { title: 'options18', needLogin: true }),// 懒加载

  
}

// 路由拦截
const onRouteBefore = ({ pathname, meta }) => {
  // 动态修改页面title
  if (meta.title !== undefined) {
    document.title = meta.title
  }
  // 根据token判断是否登陆
  const isLogin = window.sessionStorage.getItem("token") ? true : false
  // 判断未登录跳转登录页
  if (meta.needLogin) {
    if (!isLogin) {
      return '/login'
    }
  } else {
    // 清除登录的token
    window.sessionStorage.clear()
  }
}
setRouteBefore(onRouteBefore)